﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace EGuayas.Web.Notificacion
{
    public partial class AlertaInfo : ucWuc
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                var tab1 = this.TabPanel1.Items.FirstOrDefault();//comp => comp.ID.Equals("tab1")
            }
               
        }
        [DirectMethod(IDAlias = "AlertaInfo", ShowMask = true)]
        public void AddFeed(string container, string title, string url)
        {
            try{
            UserControlRendererConfig config = new UserControlRendererConfig
            {
                UserControlPath = "Notificacion/AlertaDetail.ascx",
                SingleControl = true,
                Mode = RenderMode.AddTo,
                Element = container
            };

            config.BeforeRender += delegate(ComponentAddedEventArgs e)
            {
                Ext.Net.Panel panel = (Ext.Net.Panel)e.Control;
                panel.Title = title;
                panel.Closable = false;
                panel.CustomConfig.Add(new ConfigItem("url", url, ParameterMode.Value));
            };

            UserControlRenderer.Render(config);
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
        }

        [DirectMethod(IDAlias = "AlertaInfo", ShowMask = true)]
        public void OpenTab(string container, string[] titles)
        {
            try{
            foreach (string title in titles)
            {
                //Notificacion/AlertaPost.ascx
                UserControlRendererConfig config = new UserControlRendererConfig
                {
                    UserControlPath = "Notificacion/AlertaPost.ascx",
                    SingleControl = true,
                    Mode = RenderMode.AddTo,
                    Element = container
                };

               
                config.BeforeRender += delegate(ComponentAddedEventArgs e)
                {
                    Ext.Net.Panel panel = (Ext.Net.Panel)e.Control;
                    panel.Title = title;
                    panel.Closable = true;

                    panel.CustomConfig.Add(new ConfigItem("active", "FeedViewer.FeedDetail.getRecordByTitle('" + title + "')", ParameterMode.Raw));
                    panel.CustomConfig.Add(new ConfigItem("data", "FeedViewer.FeedDetail.getRecordByTitle('" + title + "').data", ParameterMode.Raw));

                    Toolbar toolbar = (Toolbar)panel.DockedItems[0];

                    toolbar.Items[0].Visible = false;
                    toolbar.Items[0].Visible = false;
                    toolbar.Cls = "x-docked-noborder-top";
                };
                 

                UserControlRenderer.Render(config);
            }
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
        }
        protected void TabInfoAdded_tab3(object sender, ComponentAddedEventArgs e)
        {
            try
            {
            if (X.IsAjaxRequest)
            {
                return;
            }
       
            Ext.Net.Panel pnl = (Ext.Net.Panel)e.Control;
            pnl.Icon = Icon.PackageDelete;
            Ext.Net.Panel pnlChild = (Ext.Net.Panel)pnl.Items.First();
            pnlChild.Title = "Notificaciones Borrados";
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }

        }
        protected void TabInfoAdded_tab2(object sender, ComponentAddedEventArgs e)
        {
            try
            {
            if (X.IsAjaxRequest)
            {
                return;
            }
            Ext.Net.Panel pnl = (Ext.Net.Panel)e.Control;
            pnl.Icon = Icon.FolderDatabase;
            Ext.Net.Panel pnlChild = (Ext.Net.Panel)pnl.Items.First();
            pnlChild.Title = "Notificaciones Recibidas";
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
          
        
        }

        protected void TabInfoAdded_tab1(object sender, ComponentAddedEventArgs e)
        {
            try
            {
            if (X.IsAjaxRequest)
            {
                return;
            }

            Ext.Net.Panel pnl = (Ext.Net.Panel)e.Control;          
            pnl.Icon = Icon.PackageGo;
            Ext.Net.Panel pnlChild = (Ext.Net.Panel)pnl.Items.First();
            pnlChild.Title = "Notificaciones Actuales";
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }

        }
       
    }
}